<html>
<head>
    <title>总公司销售订单管理</title>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../../images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all"/>
    <script type="text/javascript" src="../../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <link rel="stylesheet" href="../../css/oksub.css">
    <style type="text/css">
        .demoTable{
            position:absolute;
            left:470px;
        }
        /*复选框居中*/
        .layui-table-cell .layui-form-checkbox[lay-skin="primary"]{
            top: 50%;
            transform: translateY(-50%);
        }

    </style>
</head>
<body>

<div>
    <div class="ok-body">
        <!--模糊搜索区域-->
        <div class="layui-row">
            <form class="layui-form layui-col-md12 ok-search">
                <input type="text" id="soNum" name="soNum" autocomplete="off"
                       class="layui-input" placeholder="总公司销售订单编号" maxlength="32">
                <input type="text" name="soPerson" autocomplete="off"
                       class="layui-input" placeholder="销售人" maxlength="5" id="soPerson">
                <input class="layui-input" placeholder="输入开始日期" lay-verify="startTime" autocomplete="off" id="startTime" name="startTime">
                <input class="layui-input" placeholder="输入结束日期"  autocomplete="off" id="endTime" name="endTime">
                <input type="text" name="soPriceMin" lay-verify="PriceMin" oninput="value = value.replace(/[^0-9.]/g, '').trim()" placeholder="￥最小总金额"  maxlength="11"
                       autocomplete="off" class="layui-input" lay-verify="PriceMin" onblur="clearNoNum(this)" id="soPriceMin">

                <input type="text" name="soPriceMax" placeholder="￥最大总金额"  oninput="value = value.replace(/[^0-9.]/g, '').trim()"  maxlength="11" id="soPriceMax"
                       autocomplete="off" class="layui-input" onblur="clearNoNum(this)" >
                <input type="text" name="soNumMin" placeholder="最小总数量" maxlength="11" id="soNumMin"
                       autocomplete="off" class="layui-input" lay-verify="soNumMin" oninput="value=value.replace(/[^\d]/g,'')"
                       onkeyup="clearNoNums(this)">
                <input type="text" name="soNumMax" placeholder="最大总数量" maxlength="11" id="soNumMax"
                       autocomplete="off" oninput="value=value.replace(/[^\d]/g,'')"
                       class="layui-input" onkeyup="clearNoNums(this)" onblur="minNumNoMaxNum(this)">

                <button class="layui-btn" lay-submit="" lay-filter="search">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
            </form>
        </div>




            </form>
        </div>
        <!--数据表格-->
        <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="isvaText">
        {{# if(d.isva == '30'){ }}
        <p class="layui-btn layui-btn-warm layui-btn-xs">分公司采购经理通过,等待分公司总经理审核</p>
        {{# }else if(d.isva == '31'){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">分公司采购经理不通过</p>
        {{#  }else if(d.isva == '40'){ }}
        <p class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理通过,等待总公司销售经理审核</p>
        {{#  }else if(d.isva == '41'){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理不通过</p>
        {{#  }else if(d.isva == '50'){ }}
        <p class="layui-btn layui-btn-warm layui-btn-xs">总公司销售经理通过,等待总公司总经理审核</p>
        {{#  }else if(d.isva == '51'){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">总公司销售经理不通过</p>
        {{#  }else if(d.isva == '60'){ }}
        <p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过,完成审核</p>
        {{#  }else if(d.isva == '61'){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>
        {{#  }else if(d.isva == '70'){ }}
        <p class="layui-btn layui-btn layui-btn-normal layui-btn-xs">未入库</p>
        {{#  }else if(d.isva == '71'){ }}
        <p class="layui-btn layui-btn layui-btn-normal layui-btn-xs">已入库</p>
        {{#  } }}
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="immTrackingLogistics"><i class="layui-icon">&#xe615;</i>查询物流详情</a>
        <a class="layui-btn layui-btn-xs" lay-event="ck"><i class="layui-icon">&#xe615;</i>查看订单详情</a>
        <a class="layui-btn layui-btn-xs" lay-event="ckSh"><i class="layui-icon">&#xe615;</i>查看审核详情</a>
    </script>


    <script src="../../../res/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

    <script>
        var openindex = null;
        var table = null;

        layui.use(['table','laydate'] , function(){
            table = layui.table ,
                laydate = layui.laydate;
            let form = layui.form;
            let roleTable = table.render({
                method:"POST",
                elem: '#test'
                ,url:'/hqMarket/showList'
                // ,toolbar: '#toolbarDemo' //开启头部工具栏，并【为其绑定左侧模板
                ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    ,layEvent: 'LAYTABLE_TIPS'
                    ,icon: 'layui-icon-tips'
                }]
                ,totalRow: true  //开启合计
                ,title: '用户数据表'
                ,height: 'full-200', cellMinWidth: 80 //最大化适应
                ,height:600
                ,cols: [[
                    // {type: 'checkbox', fixed: 'left'}
                    {field:'marketId', title:'总公司销售订单编号', minWidth:200 ,unresize: true, sort: 'true', totalRowText: '合计'}
                    ,{field:'marketMan', title:'销售人', width:200,align:'center'}
                    ,{field:'marketTime', title:'销售时间',sort: 'true', width:150,align:'center'}
                    ,{field:'marketPrice', title:'销售总金额', sort: 'true',width:200,align:'center', totalRow: true}
                    ,{field:'marketNum', title:'销售总数量',sort: 'true', minWidth:100,align:'center', totalRow: true}
                    ,{field:'remark', title:'销售说明', minWidth:200,align:'center'}
                    ,{field:'whetherValid', title:'订单状态', width:300,align:'center',templet:'#isvaText'}
                    ,{field:'optime', title:'操作时间',sort: 'true', width:200,align:'center'}
                    ,{field:'oper', title:'操作人',align:'center',width:90}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:370,align:'center'}
                ]]
                ,page: true
            });

            //添加验证规则verify
            form.verify({
                startTime: function (startTime) {
                    if(startTime!='' && $("#endTime").val()!=''){
                        let endTime = $("#endTime").val();
                        return new Date(endTime) > new Date(startTime) ? '' : "开始时间不能大于结束时间";
                    }else{
                        return "";
                    }
                },
                soNumMin:function (soNumMin) {
                    if((soNumMin-0)<($("#soNumMax").val()-0)){
                        return "";
                    }else if((soNumMin!='' && $("#soNumMax").val()!='') ){
                        let soNumMax = $("#soNumMax").val();
                        return soNumMax > soNumMin ? '' : "最小总数量不能大于最大总数量";
                    }else{
                        return "";
                    }
                },
                PriceMin:function (soPriceMin) {
                    if((soPriceMin-0)<($("#soPriceMax").val()-0)){
                        return "";
                    }else if((soPriceMin!='' && $("#soPriceMax").val()!='') ){
                        let soPriceMax = $("#soPriceMax").val();
                        return soPriceMax > soPriceMin ? '' : "最小总金额不能大于最大总金额";
                    }else{
                        return "";
                    }
                }

            });

            //日期时间选择器
            laydate.render({
                elem: "#startTime",
                theme: 'molv',
                type: "datetime"});
            laydate.render({
                elem: "#endTime",
                type: "datetime",
                theme: 'molv'
            });


            //查询条件
            form.on("submit(search)", function (data) {
                console.info(data);
                roleTable.reload({
                    where: data.field,
                    page: {curr: 1}
                });
                return false;
            });


            //监听行工具事件
            table.on('tool(test)', function(obj){//注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data;
                console.log(obj);
                if(obj.event === 'ck'){
                    console.info(data)
                    var marketId = data.marketId;
                    //sessionStorage['soId'] = soId;
                    openindex = layer.open({
                        type: 2,
                        title: '总公司销售订单详情',
                        area : ['80%' , '85%'],//弹出框大小
                        anim:1,
                        shadeClose:true,//点击也能遮罩层关闭
                        shift:1,//弹出框动画效果
                        skin: 'layui-layer-molv',//样式
                        shade: [0.8, '#393D49'] ,//显示遮罩
                        maxmin: true, //开启最大化最小化按钮
                        content: 'hqMarketdetail.html?marketId='+marketId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                }else if(obj.event === 'ckSh'){
                    console.info(data)
                    var marketId = data.branch;
                    //sessionStorage['soId'] = soId;
                    //根据总公司销售订单编号查看审核表记录
                    openindex = layer.open({
                        type: 2,
                        title: '审核详情',
                        area : ['80%' , '85%'],//弹出框大小
                        anim:1,
                        shadeClose:true,//点击也能遮罩层关闭
                        shift:1,//弹出框动画效果
                        skin: 'layui-layer-molv',//样式
                        shade: [0.8, '#393D49'] ,//显示遮罩
                        maxmin: true, //开启最大化最小化按钮
                        content: '/ok-admin/pages/audit/auditList.html?marketId='+marketId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                }else if(obj.event === "immTrackingLogistics"){
                    var id = data.branch;
                    openIndex = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['100%', '100%'], //宽高
                        title: '物流详情',
                        maxmin: true, //开启最大化最小化按钮
                        content: '/ok-admin/pages/map.html?id='+id,
                    });
                }
            });
        });
        function tishi(msg) {
            layer.msg(msg,{time:1000,icon:1},function(){
                table.reload("test");
                //window.location.reload(true);
            });
        }

        /**
         * 关闭弹出层
         */
        function closeOpen(msg){
            layer.close(openindex);
            layer.msg(msg,{time:1000,icon:1},function(){
                table.reload("test");
                //window.location.reload(true);
            });
        }
        //限制数字的输入
        function clearNoNum(obj){
            obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
            if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
                obj.value= parseFloat(obj.value);
            }
            if(obj.value.indexOf(".")==0){//第一个字符不能为.
                obj.value="";
            }
        }
        //限制数字的输入
        function clearNoNums(obj){
            obj.value = obj.value.replace(/[^\d]/g,"");
        }
        //限制最大日期不能低于最小日期
        function minDateNoMaxDate(obj){
            alert(123);
            var soDateMin = $("#soDateMin").val();
            var soDateMax = $(obj).val();
            alert("最小日期"+soDateMin+" "+"最大日期"+soDateMax);
        }
        //限制最大金额不能小于最小金额
        function minMoneyNoMaxMoney(obj){
            var soPriceMin = $("#soPriceMin").val()-0;
            var soPriceMax = $(obj).val()-0;
            if(soPriceMax < soPriceMin){
                $(obj).val("");
                $(obj).attr("placeholder","最大总金额不能低于最小总金额");
            }
        }
        //限制最大数量不能低于最小数量
        function minNumNoMaxNum(obj){
            var soNumMin = $("#soNumMin").val()-0;
            var soNumMax = $(obj).val()-0;
            if(soNumMax < soNumMin){
                $(obj).val("");
                $(obj).attr("placeholder","最大总数量不能低于最小总数量");
            }
        }
    </script>

</div>
</body>
</html>
